package org.nfIt.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * ClossName:SpringComfig
 * Pakage:org.nfIt.comfig
 * Description
 *
 * @Author L
 * @Create 2024/5/3 14:53
 * @Version 2023.1.3
 */
public class JdbcConfig {

//    简单类型注入
    @Value("${driverClassName}")
   private String driverClassName;
    @Value("${url}")
   private String url;
    @Value("${username}")
   private String username;
    @Value("${password}")
   private String password;

    //引用类型bean，在方法中添加形参
    @Bean
    public DataSource dataSource(){
        DruidDataSource ds = new DruidDataSource();
        ds.setDriverClassName(driverClassName);
        ds.setUrl(url);
        ds.setUsername(username);
        ds.setPassword(password);
        return ds;
    }

}
